package cn.alise.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import cn.alise.qdp.model.log.UserAccessLogs;
import cn.alise.qdp.service.log.UserAccessLogsService;

@Component
@Transactional(rollbackFor = Exception.class)
public class ClearLogsJob {
	
	private static final Logger logger = LoggerFactory.getLogger(ClearLogsJob.class);

	@Autowired
	private UserAccessLogsService userAccessLogsService;
	
	@Value("${clear.logs.days}")
	private int clearLogsDays;
	
	/**
	 * 删除日志数据
	 */
	@Scheduled(cron="0 0 0/1 * * ?")
	public void deleteByClearTime() {
		
		try {
			logger.info("删除日志数据计划任务--开始！");
			
			UserAccessLogs log = new UserAccessLogs();
			log.setClearTime(clearLogsDays);
			
			userAccessLogsService.deleteByClearTime(log);
			
			logger.info("删除日志数据计划任务--完成！");
			
		} catch (Exception e) {
			logger.error("删除日志数据计划任务执行异常！异常原因：{}", e);
		}
	}
}
